-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Make logging more friendly for docker #19818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…n the default interface implementation.
…e in the default interface implementation.
…d repository classes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tested out the two scenarios.
Disabling the UmbracoFille
sync in configuration prevents logging.
I could setup a custom log viewer source with the following:
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.Logging.Viewer;
using Umbraco.Cms.Core.Persistence.Repositories;
using Umbraco.Cms.Core.Scoping;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Services.OperationStatus;
using Umbraco.Cms.Infrastructure.Logging.Serilog;
using Umbraco.Cms.Infrastructure.Services.Implement;
public class LogViewerComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
builder.Services.AddUnique<ILogViewerService, CustomLogViewerService>();
builder.Services.AddUnique<ILogViewerRepository, CustomLogViewerRepository>();
}
}
public class CustomLogViewerRepository : LogViewerRepositoryBase
{
public CustomLogViewerRepository(UmbracoFileConfiguration umbracoFileConfig)
: base(umbracoFileConfig)
{
}
protected override IEnumerable<ILogEntry> GetLogs(LogTimePeriod logTimePeriod, ILogFilter logFilter)
{
return new List<LogEntry>
{
new LogEntry
{
Level = Core.Logging.LogLevel.Information,
MessageTemplateText = "This is a custom log entry: {Foo}",
RenderedMessage = "This is a custom log entry: Bar",
Timestamp = DateTime.UtcNow,
Exception = null,
Properties = new Dictionary<string, string?>
{
{ "Foo", "Bar" },
{ "MachineName", "MyServer" }
}.AsReadOnly()
}
};
}
}
public class CustomLogViewerService : LogViewerServiceBase
{
public CustomLogViewerService(
ILogViewerQueryRepository logViewerQueryRepository,
ICoreScopeProvider provider,
ILogViewerRepository logViewerRepository)
: base(
logViewerQueryRepository,
provider,
logViewerRepository)
{
}
protected override string RepositoryLoggerName => "MyLogger";
public override Task<Attempt<bool, LogViewerOperationStatus>> CanViewLogsAsync(LogTimePeriod logTimePeriod)
=> Task.FromResult(Attempt.SucceedWithStatus(LogViewerOperationStatus.Success, true));
}
As noted on the docs PR, I created an implementation of the service too. This wasn't necessary, but I think it's better to have otherwise there's some unnecessary attempts to read files from disk in the CanReadLogs
method of the default implementation.
…for the new service.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have completed updates based on pending code review points.
Related docs PR is here: umbraco/UmbracoDocs#7271
Prerequisites
Description
With docker in mind, this PR sets out to make it easier to change the default logging behaviour shipped with Umbraco by
Testing